package com.ms.game.sendgift.db;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Map;

import com.ms.game.itembox.db.ItemDAO;
import com.ms.game.itembox.db.PlayerItemModel;
import com.ms.game.sendgift.NotifyData;
import com.ms.game.sendgift.message.SendGiftAllNotifyResponse;
import com.ms.service.error.ErrorCode;
import com.xpec.c4.game.utility.GUID;
import com.xpec.c4.message.MessageTypes;
import com.xpec.c4.service.message.MessageAction;
import com.xpec.c4.service.module.task.TaskAsyncCommand;

public class LoadRecordDetailDataAsync extends TaskAsyncCommand {

	public GUID playerID;
	
	public GUID sessionID;
	/**
	 * 訂單ID
	 */
	public long orderID;
	
	public SendGiftAllNotifyResponse response;
	
	@Override
	public void asyncExecute() throws Exception {
		
		List records = SendGiftRecordDAO.loadRecordDetailByOrderID(orderID);
		
		
		ArrayList<NotifyData> notifyDatas = new ArrayList<NotifyData>();
		Iterator it = records.iterator();
		while (it.hasNext()) {
			Map map = (Map)it.next();
			String stageListStr = (String) map.get("stageList");
			SendGiftRecordLog model = (SendGiftRecordLog)map.get("SendGiftRecordLog");
			ArrayList<PlayerItemModel> sendGiftItems = ItemDAO.loadSendGiftItems(model.getOrderID());
			NotifyData data = new NotifyData(model.getPlayerGUID().toString(), model, stageListStr, sendGiftItems);
			notifyDatas.add(data);
		}
		response.recordData = notifyDatas;
	}

	@Override
	public void execute() throws Exception {
		
		response.errorCode = ErrorCode.SUCCESS;
		MessageAction.sendMessage(sessionID, MessageTypes.S_GIFT_GET_RECORD_DETAIL_RESPONSE, response);
		
	}

}
